﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BUS;

namespace ManagementBooks
{
    public partial class NXB : Form
    {
        public NXB()
        {
            InitializeComponent();
        }
        nxbBUS nxbbus = new nxbBUS();
        private void NXB_Load(object sender, EventArgs e)
        {
            try
            {

                dataGridView1.DataSource = nxbbus.showNXB();

            }
            catch { } 
        }

        private void btthem_Click(object sender, EventArgs e)
        {
            try
            {
                nxbbus.themNXB(tbtennxb.Text, tbdiachi.Text);
                NXB_Load(sender, e);
            }
            catch { } 
        }

        private void btsua_Click(object sender, EventArgs e)
        {
            try
            {
                nxbbus.suaNXB(tbmanxb.Text, tbtennxb.Text, tbdiachi.Text);
                NXB_Load(sender, e);
            }
            catch { } 
        }

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                nxbbus.xoaNXB(tbmanxb.Text);
                NXB_Load(sender, e);
            }
            catch { } 
        }

        private void btthoat_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("Bạn có chắc muốn thoát hay không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                this.Close();
                Dispose();
            }
        }

        private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            int dem = e.RowIndex;

            dataGridView1.Rows[dem].Cells[0].Value = dem + 1;
        }

        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            int dem = e.RowIndex;
            tbmanxb.Text = dataGridView1.Rows[dem].Cells["manxb"].Value.ToString();
            tbtennxb.Text = dataGridView1.Rows[dem].Cells["tennxb"].Value.ToString();
            tbdiachi.Text = dataGridView1.Rows[dem].Cells["diachi"].Value.ToString();
        }
    }
}
